package engine.logic.login
{
	import engine.net.mgr.NetMgr;
	import engine.net.mgr.SystemSender;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import newx.com.config.StaticIni;

	public class ProtectionLogin
	{
		private var _pwdMC		:	MovieClip;
		private var _valueTxt 	:	TextField;
		private var _submitBtn	:	SimpleButton;
		
		private var _container	:	Sprite;
		
		public function ProtectionLogin(mc:MovieClip,loginContainer:MovieClip)
		{
			_container	=	loginContainer;
			
			_pwdMC 		=	mc.getChildByName("niudun") as MovieClip;
			_valueTxt	= 	_pwdMC.uName;
			_valueTxt.maxChars = 8;
			_valueTxt.restrict = "0-9";
			_submitBtn	=	_pwdMC.loginBtn;
			
			addListener();
		}
		
		private function addListener():void
		{
			_submitBtn.addEventListener(MouseEvent.CLICK, onClick);
		}
		
		private function onClick(evt:MouseEvent):void
		{
			if(	""	==	_valueTxt.text )
			{
				LoginAlert.showAlert("51092" );
				return;
			}
			
			if( NetMgr.connected())
			{
				ready();
			}else
			{
				NetMgr.netConnect( LoginGroup._ip, Number(LoginGroup._port), ready );
			}
			
			function ready():void
			{
				if( LoginLogic.Unite_Url == "" )
				{
					SystemSender.getInstance().LoginNiuDunWay(LoginGroup._userName,LoginGroup._password,_valueTxt.text);
				}else
				{
					SystemSender.getInstance().LoginOtherWay(LoginGroup._userName,LoginGroup._sIdentity+ "$" + _valueTxt.text);
				}
			}
		}
		
		public function show(info:Object=null):void
		{
			WaitingForScene.end();
			
			_pwdMC.mouseChildren = _pwdMC.mouseEnabled = _pwdMC.visible = true;
			
			_container.addChild(_pwdMC);
		}
		
		public function hide():void
		{
			_pwdMC.mouseChildren = _pwdMC.mouseEnabled = _pwdMC.visible = false;
			
			if( _pwdMC.parent != null )
			{
				_pwdMC.parent.removeChild( _pwdMC );
			}
		}
	}
}